#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n,m,l,v;
    cin>>n>>m>>l>>v;
    int a[100005],b[100005];
    for(int i=1;i<=n;i++){
        int c;
        cin>>a[i]>>b[i]>>c;
        if(c!=0)return;
    }
    int maxn=0;
    for(int i=1;i<=m;i++){
        int c;cin>>c;
        maxn=max(maxn,c);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(a[i]<=maxn&&b[i]>v){
            ans++;
        }
    }
    if(ans==0){
            cout<<ans<<" "<<m<<endl;
    }
    else{
        cout<<ans<<" "<<m-1<<endl;
    }
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}
